<?php

namespace Dcat\Admin\Caijiwebinfo\Http\Controllers;

use Dcat\Admin\Caijiwebinfo\Models\CaijiwebinfoMedia;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Widgets\Tab;
use Dcat\Admin\Widgets\Alert;

class CaijiwebinfoMediaController extends AdminController
{
    /**
     * page index
     */
    public function index(Content $content)
    {
        return $content
            ->header('采集的资源管理')
            ->description('全部')
            ->breadcrumb(['text'=>'列表','uri'=>''])
            ->body($this->grid());
    }


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid =  Grid::make(new CaijiwebinfoMedia(), function (Grid $grid) {
            $grid->model()->orderBy('id','DESC');
            $grid->column('id')->sortable();
            $grid->column('cms_id','信息ID')->display(function ($cms_id){
                return "<a href='/admin/caijiwebinfo/list?id=$cms_id'>$cms_id</a>";
            });
            $grid->column('caiji_web_url','采集地址')->link();
            $grid->column('source_url','源地址')->display(function ($source_url){
                return "<a href='$source_url' target='_blank'>查看</a>";
            });
            $grid->column('local_web_url','本地url')->display(function ($local_web_url){
                return "<a href='$local_web_url' target='_blank'>查看</a>";
            });
            $grid->column('cos_web_url','云储存url')->display(function ($cos_web_url){
                return "<a href='$cos_web_url' target='_blank'>查看</a>";
            });
            //$grid->column('media_size');
            //$grid->column('source_url_md5');
            $grid->column('created_at');
            //$grid->column('updated_at')->sortable();
            $grid->disableCreateButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('id')->width(3);
                $filter->equal('cms_id','信息ID')->width(3);
                $filter->equal('caiji_web_url','采集地址')->width(3);
                $filter->equal('source_url','源地址')->width(3);
            });
        });
        $tab = Tab::make();
        $tab->addLink('信息列表', admin_url('/caijiwebinfo/list'));
        $tab->add('资源管理', $grid, true);
        $card =  Card::make('',$tab);
        return $card;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CaijiwebinfoMedia(), function (Show $show) {
            $show->field('id');
            $show->field('cms_id');
            $show->field('caiji_web_url');
            $show->field('source_url');
            $show->field('local_web_url');
            $show->field('cos_web_url');
            $show->field('media_size');
            $show->field('source_url_md5');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CaijiwebinfoMedia(), function (Form $form) {
            $form->display('id');
            $form->text('cms_id');
            $form->text('caiji_web_url');
            $form->text('source_url');
            $form->text('local_web_url');
            $form->text('cos_web_url');
            $form->text('media_size');
            $form->text('source_url_md5');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
